package com.baizhi.controller;

import com.baizhi.entity.CmfzArticle;
import com.baizhi.service.CmfzArticleService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("article")
public class CmfzArticleController  {
    @Autowired
    private CmfzArticleService cas;

    @RequestMapping("selByPage")
    public Map selByPage(int pageNo,int pageSize){
        Map<String,Object> map=new HashMap<>();
        Page<CmfzArticle> cmfzArticlePage = cas.selectByPage(pageNo, pageSize);
        map.put("code",0);
        map.put("msg","");
        map.put("data",cmfzArticlePage.getRecords());
        map.put("count",cmfzArticlePage.getTotal());
        return map;
    }

    @RequestMapping("delArticle")
    public Boolean delArticle(int id){

        try {
            cas.delete(id);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @RequestMapping("updArticle")
    public Boolean updArcticle(CmfzArticle cmfzArticle){
        try {
            cas.update(cmfzArticle);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
